<?php
/**
 * Created by PhpStorm.
 * User: patrickwu
 * Date: 2020/6/16
 * Time: 10:22
 */
namespace App\Http\Controllers\Live;

use App\Constant\RedisKeyConstant;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Redis;

class BaseController extends Controller
{
    const COME_WELCOME  =   1,
        LEAVE_WELCOME   =   5,
        FOCUS_WELCOME   =   2,
        BLOCK_WELCOME   =   3,
        UNBLOCK_WELCOME =   4;

    const WELCOME_DESC  =   [
        self::COME_WELCOME   =>  "欢迎用户%s进入直播间",
        self::LEAVE_WELCOME  =>  "用户%s离开了直播间",
        self::FOCUS_WELCOME  =>  "用户%s关注了主播",
        self::BLOCK_WELCOME  =>  "用户%s已被禁言",
        self::UNBLOCK_WELCOME=>  "用户%s已被解禁",
    ];

    protected $current_room;        //socket current name

    protected $room_id;             //live room id

    public function __construct(Request $request)
    {
        $room_id    =   $request->query->get('room_id');
        /**
         * get current name
         */
        Redis::SELECT(RedisKeyConstant::REDIS_DATABASE_NUMBER);
//        $room_id  =   Redis::GET(RedisKeyConstant::ROOM_CURRENT_NAME);

        /**
         * setting current connection room name
         */
        $this->current_room =   ($room_id ?? 70);  //'c61a8478-9793-47a9-a31c-35dc52a073d7';
        $this->room_id      =   (int) ($room_id ?? 70);
    }
}

